package com.ji.zhiqu.mapper;

import com.ji.zhiqu.model.dto.statistic.AppAnswerCountDTO;
import com.ji.zhiqu.model.dto.statistic.AppAnswerResultCountDTO;
import com.ji.zhiqu.model.entity.UserAnswer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author JKY
* @description 针对表【user_answer(用户答题记录)】的数据库操作Mapper
* @createDate 2025-03-27 17:03:33
* @Entity com.ji.zhiqu.model.entity.UserAnswer
*/
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {

    /**
     * 自定义SQL，统计热门app top 10（答题数量）
     * @return
     */
    @Select("select appId,count(userId) as answerCount " +
            "from user_answer group by appId order by answerCount desc limit 10;")
    List<AppAnswerCountDTO> doAppAnswerCount();

    /**
     * 统计某一个App的用户答案结果
     */
    @Select("select resultName,count(resultName) as resultCount from user_answer\n" +
            "where appId = #{appId} group by resultName order by resultCount desc ;")
    List<AppAnswerResultCountDTO> doAnswerResultCount(Long appId);
}





